package LeetCode.leetcode77;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        backTracking(res,path,1,n,k);
        return res;
    }
    public static void backTracking(List<List<Integer>> res,List<Integer> path,int startIndex,int n,int k){
        if (path.size() == k){
            res.add(new ArrayList<>(path));
            return;
        }
        for (int i = startIndex; i <= n - (k - path.size()) + 1; i++) {
            path.add(i);
            backTracking(res,path,i+1,n,k);
            path.remove(path.size()-1);
        }
    }
}
